package main

import (
	"DistributeCalculator/task"
	"flag"
	"fmt"
	"log"
)

func main() {
	workerID := flag.Int("workerID", 0, "workerID int")
	flag.Parse()
	worker := worker{workerID: int32(*workerID)}
	rpcClient, err := worker.connectToPrimary("8081", "127.0.0.1")
	if err != nil {
		log.Fatalf("无法连接primary, error: %v", err)
	}

	tTask, err := worker.callForPullTask(rpcClient)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf("任务%v已经开始处理\n", tTask.GetTask().GetTaskID())
	worker.ProcessTask(tTask)
	worker.callForPushResult(rpcClient, &task.WorkerResponse{
		WorkerID: worker.workerID,
		Task:     tTask.GetTask(),
	})
	fmt.Printf("任务%v已经处理完毕，已返回\n", tTask.GetTask().GetTaskID())

}
